#version 450 compatibility




layout(local_size_x = DEF_LocalSize, local_size_y = DEF_LocalSize, local_size_z = 1) in;




layout( binding = 0 ) uniform Buf_LoalParameter0 {
    ivec4 m_Box;
    ivec2 m_Offset;
    uint m_PointNum;
    uint m_IntersectPointNum;
    uint m_Func;
};

layout(std430, binding = 1) buffer Buf_GlobalParameter1 {
    vec2 m_LinePoint[];
};
layout(std430, binding = 2) buffer Buf_GlobalParameter2 {
    uvec2 m_PointStep[];
};
layout(std430, binding = 3) buffer Buf_GlobalParameter3 {
    uvec2 m_PointRange[];
};

void main(){
    //const uint id = (gl_WorkGroupID.y * gl_NumWorkGroups.x) + gl_WorkGroupID.x;
    const uint id = (gl_WorkGroupID.y * gl_NumWorkGroups.x) + gl_WorkGroupID.x;

    if(id<m_IntersectPointNum){
        uint VertRangeID = m_PointRange[id].x;
        uint endID = m_PointRange[id].x + 1;
        if(endID>=m_PointNum) endID = 0;

        vec2 APoint = m_LinePoint[ VertRangeID + 1 ];
        vec2 BPoint = m_LinePoint[ endID + 1 ];

        vec2 Step = normalize(BPoint - APoint);
        //---------------Y轴坐标-----------------
        uvec2 range = m_PointStep[ VertRangeID ];
        
        if(Step.y<0){
            BPoint.y = int(id) - int(range.x);
        } else BPoint.y = int(range.x) - int(id);
        
        //float X = 1 * Step.x;
        //BPoint.x = BPoint.y * (Step.x / Step.y);
        BPoint.x = BPoint.y * (Step.x / Step.y);
        
        m_PointRange[id].x = packHalf2x16(APoint+BPoint);
    }
}